package com.hades.example.java.refactoring.after.c10.c10_14_replace_error_code_with_exception.v1;

public class Account {
    int _balance;

    // step 1 :
//    int withdraw(int amount) {
//        try {
//            newWithdraw(amount);
//            _balance -= amount;
//            return 0;
//        } catch (IllegalArgumentException ex) {
//            handleOverdrawn();
//            return -1;
//        }
//    }

//    private void handleOverdrawn() {
//
//    }

    //    void newWithdraw(int amount) throws IllegalArgumentException {
//        if (amount > _balance) {
//            throw new IllegalArgumentException("Amount too large");
//        }
//        _balance -= amount;
//    }
    // step 2 : rename newWithdraw -> withdraw

    void withdraw(int amount) throws IllegalArgumentException {
        if (amount > _balance) {
            throw new IllegalArgumentException("Amount too large");
        }
        _balance -= amount;
    }
}